//==============================================================================
//
//               Copyright (C) 2002  Dick van Oudheusden
//  
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//==============================================================================
// 
//  $Date: 2003-10-31 08:12:34 $ $Revision: 1.1 $
//
//==============================================================================

#include <stdlib.h>

#include "ofc/config.h"

#include "ofc/DText.h"
#include "ofc/DData.h"
#include "ofc/DCalendar.h"

#include "DInc.h"
#include "DTest.h"

//-Misc------------------------------------------------------------------------

void DCalendar_test()
{
  DCalendar *cal = [DCalendar alloc];

  STARTTEST();
  
  [cal init :2003];
 
  TEST(([cal year] == 2003) && ([cal month] == DCL_ALL_MONTHS));
  
  [DCalendar firstWeekDay :DCL_MONDAY];

  TEST([DCalendar firstWeekDay] == DCL_MONDAY);
  
  {
    DText *text = [cal toText ];
    int    len  = [text length];
    long   cnt  = 0;
    int    i    = 0;
    
#if 0
    printf([text cstring]);
#endif
    
    for (i = 0; i < len; i++)
    {
      cnt += [text get :i];
    }

    TEST(cnt == 105858);
      
    [text free];
  }
  
  [DCalendar firstWeekDay :DCL_SUNDAY];
  
  TEST([DCalendar firstWeekDay] == DCL_SUNDAY);
  
  [cal year  :2004];
  {
    DData *data   = [cal toData];
    int    size   = [data size ];
    int    i      = 0;
    long   cnt    = 0;
    
    while (i < size)
    {
      unsigned char ch = [data get :i++];

#if 0
      printf("%2d ", ch);

      if (i % 7 == 0)
        printf("\n");
#endif
      cnt += ch;;
    }

    TEST(cnt == 5767);
    
    [data free];
  }    
  
  [cal free];

  STOPTEST();
}

